import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:play_android/com/zhihaoliang/http/ResultData.dart';
import 'package:play_android/com/zhihaoliang/http/HttpException.dart';
import 'package:play_android/com/zhihaoliang/play/login/view/LoginPage.dart';

///  ***************************************************************************
///  所有Repository异步处理的基类
///  **************************************************************************

abstract class BaseRepository<T> {
  Future<T> fetch([String url, Map<String, String> map]) async {
    ResultData resultData = await fetchResultData(url, map);
    if (resultData.errorCode == 0) {
      return await fetchModel(resultData.data);
    }

    throw new HttpException(resultData.errorMsg, url, resultData.errorCode);
  }

  Future<ResultData> fetchResultData([String url, Map<String, dynamic> map]);

  T fetchModel(Map<String, dynamic> map);
}
